﻿using D.Medicalcare.Domain.Entities;
using D.Medicalcare.ErrorCode;
using D.Medicalcare.Infrastructure.Interfaces;
using D.Medicalcare.Read.API.Application.Command.PhysicalexaminationCommand;
using MediatR;

namespace D.Medicalcare.Read.API.Application.Handler.PhysicalexaminationHarder
{
    public class OrderPhysicalexaminationHarder : IRequestHandler<OrderPhysicalexaminationCommand, APIResult<Physicalexamination>>
    {

        private readonly IBaseRepository<Physicalexamination> repository;

        public OrderPhysicalexaminationHarder(IBaseRepository<Physicalexamination> repository)
        {
            this.repository = repository;
        }

        public Task<APIResult<Physicalexamination>> Handle(OrderPhysicalexaminationCommand request, CancellationToken cancellationToken)
        {
            APIResult<Physicalexamination> result = new APIResult<Physicalexamination>();
            result.Code = APIEnum.Mvc;
            result.Msg = "查询成功";
            var list = repository.GetAll().OrderByDescending(x => x.physicalId).ToList()[0];
            result.Data = list;

            return Task.FromResult(result);
        }
    }
}
